#pragma once

#include "QSPrerequisites.h"
#include "QSSystems.h"
#include "QSEvents.h"

namespace QS
{
	class EventSystemImpl : public EventSystem
	{
	public:
		EventSystemImpl(Engine* e) : EventSystem(e) {}
		virtual ~EventSystemImpl(){}

		virtual void initialize();
		virtual void shutdown();
		virtual void update();
	
		virtual void queueEvent(const Event&);
		virtual void postEvent(const Event&);

		virtual void addEventListener(EventListener* l);
		virtual void removeEventListener(EventListener* l);
	private:	
		typedef std::queue<Event> EventQueue;
		typedef std::vector<EventListener*> EventListenerList;

		void dispatchEvent(EventQueue&);
		void swapQueues();

		//We use two event queues so we dont get stuck in an infinite loop
		//dispatching and queuing events.
		EventQueue mFrontQueue, mBackQueue;
		EventListenerList mListeners;
	};
}